/*
 * @Author: wangzhichiao<https://github.com/wzc570738205>
 * @Date: 2020-03-23 17:28:07
 * @LastEditors: wangzhichiao<https://github.com/wzc570738205>
 * @LastEditTime: 2020-05-10 16:54:24
 */
import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
import userLayout from "@/layout/user";

// 组织机构
const system1 = [
  {
    path: "/dashbord",
    name: "dashbord",
    redirect: "/home",
    component: Layout,
    children: [
      {
        path: "/home",
        name: "home",
        meta: { title: "首页", icon: "Organization" },
        component: () => import("@/views/home/index"),
      },
      {
        path: "/home/map",
        name: "map",
        meta: { title: "首页", icon: "Organization" },
        component: () => import("@/views/home/map"),
      },
      {
        path: "/project",
        name: "project",
        meta: { title: "工程管理", icon: "Organization" },
        component: () => import("@/views/project/index"),
      },
      {
        path: "/project/view",
        name: "projectview",
        meta: { title: "工程管理-项目概览", icon: "Organization" },
        component: () => import("@/views/projectview/index"),
      },
      {
        path: "/project/detail",
        name: "projectdetail",
        meta: { title: "工程管理-项目详情", icon: "Organization" },
        component: () => import("@/views/project/detail"),
      },
      {
        path: "/project/add",
        name: "add",
        meta: { title: "项目列表-新增", icon: "Organization" },
        component: () => import("@/views/project/add"),
      },
    ],
  },
];
export const routeObject = {
  system1,
};
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/one",
    component: () => import("@/views/one/home"),
    hidden: true,
  },
  ...system1,
  { path: "/", redirect: "/login" },
  ,
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  { path: "*", redirect: "/404" },
];

//实例化vue的时候只挂载constantRouter
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
